import { Block, View,Text } from '@tarojs/components'
import { useSelector } from 'react-redux'
import { useEffect, useState } from 'react'
import changeData from './changeData.wxs'

function ContactInfo({ card }) {
  const __authorizePhoneStatus = useSelector(state => state.userInfo.__authorizePhoneStatus);
  const [phone, setPhone] = useState('')
  // console.log('authorizeStatus', card);
  // useEffect(() => {
  //   if (!__authorizePhoneStatus || !card) return
  //   const p = changeData.phoneStatus(
  //     card.mobile,
  //     __authorizePhoneStatus.authorizeStatus,
  //     card.onlyShowPhoneForExchangeCard
  //   )
  //   setPhone(p)
  // }, [__authorizePhoneStatus, card])

  return (
    <Block>

      <View View className='card-contacts' >
        {
          card.options.map((item, index) => {
            return (
              <Block key={item.index}>
                {item.type === 'mobile' || item.type === 'wechat' ? (
                  <View className='card-contact-item pr'>
                    <Text
                      className={'card-contact-icon iconfont ' + item.icon}
                    ></Text>
                    <View className='card-contact-value'>
                      {
                        phone.phone
                      }
                    </View>
                    <View className='card-contact-action'>
                      {changeData.phoneStatus(
                        item.value,
                        __authorizePhoneStatus.authorizeStatus,
                        item.type == 'mobile'
                          ? card.onlyShowPhoneForExchangeCard
                          : card.onlyShowWeChatForExchangeCard
                      ).status != 1
                        ? item.type == 'mobile'
                          ? '交换电话'
                          : '交换微信'
                        : item.title}
                    </View>
                    {/* {!__userInfo.isAuthUserInfo ? (
                  <LoginButton
                    onLogined={this.handleCardOptions}
                    data-index={index}
                    data-from='userinfo'
                    userInfo={__userInfo}
                  ></LoginButton>
                ) : __authorizePhoneStatus.authorizeStatus !== 1 ? (
                  <CoverForm
                    data-index={index}
                    data-from='phone'
                    type={3}
                    onPhoneauthcomplete={this.handleCardOptions}
                  ></CoverForm>
                ) : (
                  <CoverForm
                    data-index={index}
                    onClick={this.handleCardOptions}
                  ></CoverForm>
                )} */}
                  </View>
                ) : (
                  <View className='card-contact-item pr'>
                    <Text
                      className={'card-contact-icon iconfont ' + item.icon}
                    ></Text>
                    <View className='card-contact-value'>{item.value}</View>
                    <View className='card-contact-action'>{item.title}</View>
                    {/* <CoverForm
                  data-index={index}
                  onClick={this.handleCardOptions}
                ></CoverForm> */}
                  </View>
                )}
                {/*  非电话及微信  */}
              </Block>
            )
          })
        }
      </View>
    </Block>
  )


}
export { ContactInfo }